<template>
  <div>
      <table>
          <tr>
              <th>名称</th>
              <th>积分</th>
              <th>操作</th>
          </tr>
          <tr v-for="user in user_list" :key="user.id">
              <td>{{user.username}}</td>
              <td>{{user.score}}</td>
              <td><input type="button" value="+" @click="add(user.id)"> <input type="button" value="-" @click="sub(user.id)"></td>
          </tr>
      </table>
  </div>
</template>

<script>
export default {
    data(){
        return {
            user_list:[]
        }
    },
    methods:{
        add(id){
            this.axios.put("/users",{"id":id,"num":5}).then(resp=>{
                console.log(resp.data)
                this.$router.go(0)
            })
        },
        sub(id){
             this.axios.put("/users",{"id":id,"num":-5}).then(resp=>{
                console.log(resp.data)
                this.$router.go(0)
            })
        }
    },
    created(){
        this.axios.get("/users").then(resp=>{
            console.log(resp.data)
            this.user_list=resp.data
        })
    }
}
</script>

<style>

</style>